# 元组习题
# 1.给定一个不确定长度的元组，如何使用元组解包来将前三个值分别赋给三个变量？
# tup1 = (1, 2, 3, 4, 5, 6)
# a, b, c = None, None, None
# if len(tup1) < 3 :
#    print(a,b,c)
# else:
#  a,b,c=tup1[:3:]
# print(a, b, c)
# # 2.计算元组长度（不可使用len()）
# tup2=(1,2,3,4,5,89,7,89)
# count_times=0
# for i in tup2:
#   count_times += 1
# print(count_times)
# print('第三题')
# 3.查找元祖中元素，移除每个元素的空格，生成新的元组
# tup3=("alec", " aric", "Alex ", "T on y", "rai n") ->("alec", "aric", "Alex ", "Tony", "rain")
# tup3=("alec", " aric", "Alex ", "T on y", "rai n")
# result_tup=()
# for i in tup3:
#     if ' ' in i:
#         result_tup+=(''.join(i.split(' ')),)
#     else:
#         result_tup+=(i,)
# print(result_tup)
# 4.给定一个元组，查找以 a 或 A 开头 并且以 c 结尾的所有元素，返回一个新元组
print('第四题')
tup4 = ("alec", "aric", "Alex ", "T on y", "rai n")
result_tup4 = ()
for i in tup4:
    if i[0] in ('a', 'A') and i[-1] == 'c':
        result_tup4 += (i,)
# print(result_tup4)
#
# # 5.有一个嵌套元组((1, 2), (3, 4), (5, 6))，将其解包成六个单独的变量，仅针对这个元组来解包，不要考虑其他元组
tup5 = ((1, 2), (3, 4), (5, 6))
(a,b),(c,d),(e,f) = tup5[0],tup5[1],tup5[2]
a,b = tup5[0]
c,d = tup5[1]
e,f = tup5[2]
print(a,b,c,d,e,f)





